package datafeed;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Random;


public class TestDataFeed implements IDataFeed {
	
	private static TestDataFeed m_instance;
	public static TestDataFeed getInstance() {
		if(m_instance == null)
			m_instance = new TestDataFeed();
		return m_instance;
	}
	
	private List<String> items = new ArrayList<String>();
	
	private TestDataFeed() {
		items.add("Temperature");
		items.add("Kilowatt Hours Used");
		items.add("Solar Panel Output");
		items.add("Wind Speed");
		items.add("Traffic");
		items.add("HVAC Load");
		items.add("WiFi Users");
	}
	
	@Override
	public void getTimeScales(List<String> timeScales) {
		timeScales.clear();
		timeScales.add("hour");
		timeScales.add("day");
		timeScales.add("week");
	}

	@Override
	public void getDataItems(List<String> dataItems) {
		dataItems.clear();
		for(String s : items) {
			dataItems.add(s);
		}
	}

	@Override
	public void getCategories(List<String> categories) {
		categories.clear();
		categories.add("Murdock");
		categories.add("Science Center");
	}

	@Override
	public void getDataItemsByCategory(List<String> dataItems, String category) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getChartData(Map<String, List<DataPoint>> data,
			Calendar start, Calendar end, int numPoints, List<String> dataItems)
			throws Exception {
		for(String s : dataItems) {
			boolean found = false;
			for(String item : items) {
				if(s.equals(item)) found = true;
			}
			if(!found) throw new Exception("IDataFeed: Invalid data item: " + s);
			List<DataPoint> dataList = new ArrayList<DataPoint>();
			Random rand = new Random();
			for(long i = 0; i < numPoints; i++) 
				dataList.add(new DataPoint(Calendar.getInstance().getTime(), rand.nextDouble()*100));
			data.put(s, dataList);
		}
		return "Time";
	}
}
